package com.shu.socket.one2one;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * @author ssm
 * @version V1.0
 * @description:
 * @date 2019/2/20 19:40
 */

public class SocketClient {

  public static void main(String[] args) throws IOException {
    try {
      Socket socket = new Socket("localhost", 8888);
      PrintWriter writer = new PrintWriter(socket.getOutputStream(), true);
      writer.println("hello server");
      writer.flush();

      BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
      while (true) {
        String serverDate = reader.readLine();
        if (serverDate == null) {
          break;
        }
        System.out.println(serverDate);

      }

      writer.close();
      socket.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
